package com.jindy.module.AssetRepair.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.AssetRepair.domain.AssetRepair;
import com.jindy.module.AssetRepair.service.IAssetRepairService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 资产报修Controller
 * 
 * @author jindy
 * @date 2023-04-24
 */
@RestController
@RequestMapping("/module/AssetRepair")
public class AssetRepairController extends BaseController
{
    @Autowired
    private IAssetRepairService assetRepairService;

    /**
     * 查询资产报修列表
     */
    @PreAuthorize("@ss.hasPermi('module:AssetRepair:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetRepair assetRepair)
    {
        startPage();
        List<AssetRepair> list = assetRepairService.selectAssetRepairList(assetRepair);
        return getDataTable(list);
    }

    /**
     * 导出资产报修列表
     */
    @PreAuthorize("@ss.hasPermi('module:AssetRepair:export')")
    @Log(title = "资产报修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetRepair assetRepair)
    {
        List<AssetRepair> list = assetRepairService.selectAssetRepairList(assetRepair);
        ExcelUtil<AssetRepair> util = new ExcelUtil<AssetRepair>(AssetRepair.class);
        util.exportExcel(response, list, "资产报修数据");
    }

    /**
     * 获取资产报修详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:AssetRepair:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(assetRepairService.selectAssetRepairById(id));
    }

    /**
     * 新增资产报修
     */
    @PreAuthorize("@ss.hasPermi('module:AssetRepair:add')")
    @Log(title = "资产报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetRepair assetRepair)
    {
        return toAjax(assetRepairService.insertAssetRepair(assetRepair));
    }

    /**
     * 修改资产报修
     */
    @PreAuthorize("@ss.hasPermi('module:AssetRepair:edit')")
    @Log(title = "资产报修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetRepair assetRepair)
    {
        return toAjax(assetRepairService.updateAssetRepair(assetRepair));
    }

    /**
     * 删除资产报修
     */
    @PreAuthorize("@ss.hasPermi('module:AssetRepair:remove')")
    @Log(title = "资产报修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetRepairService.deleteAssetRepairByIds(ids));
    }

    /**
     * 维修成功
     */
    @PreAuthorize("@ss.hasPermi('module:AssetRepair:updateRepairSuccess')")
    @Log(title = "维修成功", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRepairSuccess")
    public AjaxResult updateRepairSuccess(@RequestBody AssetRepair assetRepair)
    {
        return toAjax(assetRepairService.updateRepairSuccess(assetRepair));
    }

    /**
     * 维修失败
     */
    @PreAuthorize("@ss.hasPermi('module:AssetRepair:updateRepairFail')")
    @Log(title = "维修失败", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRepairFail")
    public AjaxResult updateRepairFail(@RequestBody AssetRepair assetRepair)
    {
        return toAjax(assetRepairService.updateRepairFail(assetRepair));
    }

}
